package com.yj.springbootmiaosha.service;

import com.yj.springbootmiaosha.redisLock.RedisLock;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * spring task 定时任务
 */
@Service
@Slf4j
public class SchedulerService {

    @Resource
    private RedisTemplate redisTemplate;


    //@Scheduled(cron = "0/5 * * * * *")
    public void sendMsg(){

        try(RedisLock redisLock = new RedisLock(redisTemplate,"autoSendMsg",30)){
            if (redisLock.getLock()){
                log.info("向185XXXXXXXX 发送短信！");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
